<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="com.qxf.util.db.PageDivision"%>
<%@page import="com.qxf.dao.AdpositionMgtDao"%>
<%@page import="com.qxf.model.beans.AdpBean"%>
<%@page import="com.qxf.util.Constants"%>
<%@page import="com.qxf.model.beans.UserSession"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="top.jsp"></jsp:include>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="css/jquery-ui-1.8.17.custom.css" />
<link type="text/css" rel="stylesheet" href="css/adpmgt.css" />
<script type="text/javascript" src="js/jquery-ui-1.8.17.custom.min.js"></script>
<script type="text/javascript" src="js/adpmgt.js"></script>
<title>广告位管理</title>
</head>
<body>
<% 
	int pageSize = 10;
	int currentPage = 1;
	String currentPageString = request.getParameter("currentPage");
	UserSession userInfo = (UserSession)session.getAttribute(Constants.SESSION_KEY);
	if(userInfo==null || !userInfo.isLogin()) {
		response.sendRedirect("index.jsp");
		return;
	}
	if(currentPageString!=null&&!"".equals(currentPageString)) {
		currentPage = Integer.parseInt(currentPageString);
	}
	StringBuffer searchSQL = new StringBuffer();
	searchSQL.append("and t.activity_id = '" + userInfo.getActivityInfo().getActivityId() + "'");
	String countSql = "select a.ad_id as ad_id, a.ad_name as ad_name, a.ad_url as ad_url, a.ad_clickcount as ad_clickcount," +
					" m.media_id as media_id, m.media_name as media_name, t.activity_id as activity_id" +
					" from tb_ad a" +
					" left join tb_media m on a.media_id=m.media_id" +
					" left join tb_activity t on a.activity_id=t.activity_id" +
				 	" where 1=1 " +
				 	(searchSQL!=null?(" " + searchSQL) : "");
	PageDivision pd = new PageDivision(currentPage, pageSize, countSql);
	List<AdpBean> adpList = AdpositionMgtDao.getAdpList((searchSQL.length()>0?searchSQL.toString():"") + " order by ad_id", pd);
%>
	<div class="ad_title">
		<p><span class="span_title">广告位管理</span></p>
	</div>
	<!-- 表头 -->
	<div class="ad_tableTitle">
		<ul id="ad_item" class="ad_item_title">
		  <li class="adItem_info adItem_info_mediaName adItem_title">媒体</li>
		  <li class="adItem_info adItem_info_adName adItem_title">广告位</li>
		  <li class="adItem_info adItem_info_count adItem_title">点击数</li>
		  <li class="adItem_info adItem_info_url adItem_title">广告链接</li>
		  <li class="adItem_op adItem_title_op adItem_title">操作</li>
		</ul>
	</div>
	<div class="ad_table">
<%
	int iRecord = 1;
	for(AdpBean adp:adpList) {
		if(iRecord%2 == 1) {
%>
		<ul id="ad_item" class="ad_item_odd">
		  <input class="adpId" type="hidden" value="<%=adp.getAdId() %>" />
		  <li class="adItem_info adItem_info_mediaName"><%=adp.getMediaName() %></li>
		  <li class="adItem_info adItem_info_adName"><%=adp.getAdName() %></li>
		  <li class="adItem_info adItem_info_count"><%=adp.getCount() %></li>
		  <li class="adItem_info adItem_info_url">
		  	<%if(null == adp.getAdUrl() || adp.getAdUrl().trim().length() == 0) {%>
		  	<a class="generateUrl" href="#">生成链接</a>
		  	<%} else {%>
		  	<span class="spanAdurl"><%=adp.getAdUrl() %></span>
		  	<a class="copyUrl" href="#">复制链接</a>
		  	<%}%>
		  </li>
		  <li class="adItem_op"><a class="adDelete" href="#">删除</a></li>
		  <li class="adItem_op"><a class="adEdit" href="#">编辑</a></li>
		</ul>
<%
		} else {
%>
		<ul class="ad_item_even">
		  <input class="adpId" type="hidden" value="<%=adp.getAdId() %>" />
		  <li class="adItem_info adItem_info_mediaName"><%=adp.getMediaName() %></li>
		  <li class="adItem_info adItem_info_adName"><%=adp.getAdName() %></li>
		  <li class="adItem_info adItem_info_count"><%=adp.getCount() %></li>
		  <li class="adItem_info adItem_info_url">
		  	<%if(adp.getAdUrl() == null || adp.getAdUrl().trim().length() == 0) {%>
		  	<a class="generateUrl" href="#">生成链接</a>
		  	<%} else {%>
		  	<span class="spanAdurl"><%=adp.getAdUrl() %></span>
		  	<a class="copyUrl" href="#">复制链接</a>
		  	<%}%>
		  </li>
		  <li class="adItem_op"><a class="adDelete" href="#">删除</a></li>
		  <li class="adItem_op"><a class="adEdit" href="#">编辑</a></li>
		</ul>
<%
		}
		iRecord++;
	}
	if(iRecord <= pageSize+1) {
		for(int i=iRecord;i <= pageSize+1; i++) {
			if(i == iRecord && iRecord%2 == 1) {
%>
		<ul id="ad_addNewItem" class="ad_item_odd ad_addNewItem_out"></ul>
<%
			} else if(i == iRecord && iRecord%2 == 0) {
%>
		<ul id="ad_addNewItem" class="ad_item_even ad_addNewItem_out"></ul>
<%
			} else {
%>
				<ul class="ad_item_nodata"></ul>
<%
			}
		}
	}
%>
	</div>
	<div class="dividePage">
<%
	if(pd!=null&&pd.getTotalPage()>1){
%>
	<span><% pd.showPageList(out, "adpmgt.jsp?currentPage=");%></span>
<% 
	}
%>
	</div>
	
	<!-- new ad dialog -->
	<div id="ad_dialog" style="display:none">
		<ul>
			<li class="dialogItem">
				<label class="dialogLabel" for="dialogMedia">媒体：</label>
				<select id="dialogMedia" class="dialogParam"></select>
				<a id="dialogNewMedia" href="#">新增</a>
			</li>
			<li class="dialogItem">
				<label class="dialogLabel" for="dialogAd">广告位：</label>
				<input id="dialogAd" class="dialogParam" />
			</li>
			<li class="dialogItem">
				<label class="dialogLabel" for="dialogUrl">链接：</label>
				<input id="dialogUrl" class="dialogParam"  />
				<a id="dialogGenerateUrl" href="#">生成</a>
			</li>
		</ul>
	</div>
	
	<!-- new media dialog -->
	<div id="media_dialog" style="display:none">
		<ul>
			<li class="media_dialog_item">
				<label for="media_dialog_mediaName">媒体名：</label>
				<input id="media_dialog_mediaName" />
				<!--<input id="media_dialog_newMedia" type="button" value="增加" />-->
			</li>
			<!-- 
			<li class="media_dialog_item">
				<select id="media_dialog_mediaSel" size="5"></select>
			</li>
			<li class="media_dialog_item">
				<input id="media_dialog_deleteMedia" type="button" value="删除选中媒体">
			</li>
			-->
		</ul>
	</div>
</body>
</html>